<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /** @var $this Mage_Adminhtml_Block_Sales_Order_View_Tab_Info */ ?>
<?php $_order = $this->getOrder() ?>
<div>
    <div id="order-messages">
        <?php echo $this->getChildHtml('order_messages') ?>
    </div>
    <?php echo $this->getChildHtml('order_info') ?>
    <input type="hidden" name="order_id" value="<?php echo $_order->getId() ?>"/>
    <?php if ($_order->getIsVirtual()): ?>
    <div class="box-right">
    <?php else: ?>
    <div class="box-left">
    <?php endif; ?>
        <!--Payment Method-->
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4 class="icon-head head-payment-method"><?php echo Mage::helper('sales')->__('Payment Information') ?></h4>
            </div>
            <fieldset>
                <?php echo $this->getPaymentHtml() ?>
                <div><?php echo Mage::helper('sales')->__('Order was placed using %s', $_order->getOrderCurrencyCode()) ?></div>
            </fieldset>
        </div>
    </div>
    <?php if (!$_order->getIsVirtual()): ?>
    <div class="box-right">
        <!--Shipping Method-->
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4 class="icon-head head-shipping-method"><?php echo Mage::helper('sales')->__('Shipping &amp; Handling Information') ?></h4>
            </div>
            <fieldset>
                <?php  if ($_order->getTracksCollection()->count()) : ?>
                <a href="#" id="linkId" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')" title="<?php echo $this->quoteEscape($this->__('Track Order')) ?>"><?php echo $this->__('Track Order') ?></a>
                <br/>
                <?php endif; ?>
                <?php if ($_order->getShippingDescription()): ?>
                    <strong><?php echo $this->escapeHtml($_order->getShippingDescription()) ?></strong>

                    <?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
                        <?php $_excl = $this->displayShippingPriceInclTax($_order); ?>
                    <?php else: ?>
                        <?php $_excl = $this->displayPriceAttribute('shipping_amount', false, ' '); ?>
                    <?php endif; ?>
                    <?php $_incl = $this->displayShippingPriceInclTax($_order); ?>

                    <?php echo $_excl; ?>
                    <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                        (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                    <?php endif; ?>
                <?php else: ?>
                    <?php echo $this->helper('sales')->__('No shipping information available'); ?>
                <?php endif; ?>
            </fieldset>
        </div>
    </div>
    <?php endif; ?>
    <div class="clear"></div>
    <?php echo $this->getGiftOptionsHtml() ?>
    <div class="clear"></div>
    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('Items Ordered') ?></h4>
        </div>
    </div>
    <?php echo $this->getItemsHtml() ?>
    <div class="clear"></div>
    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('退款记录') ?></h4>
        </div>
    </div>
    <?php
        $order = $this->getOrder();
        $collection = Mage::getResourceModel('sales/order_creditmemo_grid_collection')->setOrderFilter($order);
        $_items = array();
        $i = 0;
        foreach ($collection as  $value) {
            $models[$i] = Mage::getResourceModel('sales/order_creditmemo_item_collection')
                ->setCreditmemoFilter($value->getId());
            foreach ($models[$i] as $item) {
                    $_items[$i][] =  $item;
            }
        }
       
     ?>
        <div class="grid np">
        <div class="hor-scroll">
            <table cellspacing="0" class="data order-tables">
                <col />
                <col width="1" />
                <col width="1" />
                <col width="1" />
                <col width="1" />
                <col width="1" />
                <col width="1" />
                <thead>
                <tr class="headings">
                    <th><?php echo $this->helper('sales')->__('Product') ?></th>
                    <th><?php echo $this->helper('sales')->__('Price') ?></th>
                    <th class="a-center"><?php echo $this->helper('sales')->__('Qty') ?></th>
                    <th><?php echo $this->helper('sales')->__('Subtotal') ?></th>
                    <th><span class="nobr"><?php echo $this->helper('sales')->__('Tax Amount') ?></span></th>
                    <th><span class="nobr"><?php echo $this->helper('sales')->__('Discount Amount') ?></span></th>
                    <th class="last"><span class="nobr"><?php echo $this->helper('sales')->__('Row Total') ?></span></th>
                </tr>
                </thead>
                <?php if($_items): ?>
                <?php foreach ($_items as $value):?>
                <?php foreach ($value as $_item): ?>
                <tbody class="<?php echo  'even' ?>">
                    <tr>
                        <td><h5><?php echo $_item->getName(); ?></h5><div><strong>sku:<?php echo $_item->getSku(); ?></strong></div></td>
                        <td class="a-center"><?php echo Mage::helper("core")->formatPrice($_item->getBasePrice(),true); ?></td>
                        <td class="a-center"><?php echo $_item->getQty(); ?></td>
                        <td class="a-center"><?php echo Mage::helper("core")->formatPrice($_item->getRowTotal(),true); ?></td>
                        <td class="a-center"><?php echo Mage::helper("core")->formatPrice($_item->getTaxAmount(),true); ?></td>
                        <td class="a-center"><?php echo Mage::helper("core")->formatPrice($_item->getDiscountAmount()?$_item->getDiscountAmount():0,true); ?></td>
                        <td class="a-center"><?php echo Mage::helper("core")->formatPrice($_item->getRowTotalInclTax(),true); ?></td>
                    </tr>
                </tbody>
                <?php endforeach; ?>
                <?php endforeach; ?>
                <?php else: ?>
                <tr><td colspan="7" class="a-center">没有退款记录</td></tr>
                <?php endif; ?>
                            </table>
                        </div>
                        </div>
                        <br />

    <div class="clear"></div>

    <div class="box-left">
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4><?php echo Mage::helper('sales')->__('Comments History') ?></h4>
            </div>
            <fieldset><?php echo $this->getChildHtml('order_history') ?></fieldset>
        </div>
    </div>
    <div class="box-right entry-edit">
        <div class="entry-edit-head"><h4><?php echo Mage::helper('sales')->__('Order Totals') ?></h4></div>
        <div class="order-totals"><?php echo $this->getChildHtml('order_totals') ?></div>
    </div>
    <div class="clear"></div>
</div>

<?php echo $this->getChildHtml('popup_window');?>
<script type="text/javascript">
//<![CDATA[
    /**
     * Retrieve gift options tooltip content
     */
    function getGiftOptionsTooltipContent(itemId) {
        var contentLines = [];
        var headerLine = null;
        var contentLine = null;

        $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
            if (element.down(0)) {
                headerLine = element.down(0).innerHTML;
                contentLine = element.down(0).next().innerHTML;
                if (contentLine.length > 30) {
                    contentLine = contentLine.slice(0,30) + '...';
                }
                contentLines.push(headerLine + ' ' + contentLine);
            }
        });
        return contentLines.join('<br/>');
    }
    giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
//]]>
</script>
